Skip to content

COSMIC applet + shared battery UX, udev fix, XInput charging - #1

Merged
vdemonchy merged 19 commits into
mainfrom
cosmic-applet
Jun 5, 2026
Merged

vdemonchy merged 19 commits into
mainfrom
cosmic-applet

Conversation

@vdemonchy

@vdemonchy vdemonchy commented Jun 3, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a native libcosmic panel applet as a second frontend for the cyclone2 daemon (bringing the battery indicator to COSMIC / CachyOS at parity with the GNOME extension), and builds out a shared battery UX across both frontends: configurable low-battery notifications, an always-visible charge state, a level-colored controller icon that breathes while charging, and configurable thresholds. Also fixes a CachyOS udev bug and the reverse-engineered XInput charging flag, and cleans up the public naming.

Highlights

COSMIC applet (new frontend)

  • New cosmic-applet/ Rust crate (libcosmic pinned), implementing the daemon's file-only contract: reads the runtime state JSON, writes config.json.
  • Single cohesive panel button (icon + optional text) via autosize_window.
  • Popup with mode/battery details and settings (persisted via cosmic-config).

Shared battery UX (COSMIC applet + GNOME extension)

  • Controller icon tinted by battery level — green / yellow / red, with configurable thresholds (defaults 60 / 25; green constrained above yellow).
  • Breathing animation while charging — matched feel across both frontends (~2s cycle, sine easing, ~40% floor): COSMIC pulses icon brightness, GNOME pulses opacity.
  • Always-visible charge state in the popup/menu (— Charging / — On battery).
  • Simplified settings: display = Icon only / Icon + text; controller icon always shown; Mode: → Cyclone 2 mode:.

Configurable low-battery notifications (daemon)

  • Daemon posts a desktop notification (via gdbus, no D-Bus dependency) when the battery first drops to/below a configurable threshold (0–50%, default 20%, 0 disables). Edge-triggered with hysteresis; re-arms on charge/disconnect; ignores stale/unknown readings. Works accurately in all modes — including XInput/DS4, which UPower can't report correctly.

Fixes

  • udev (Arch/CachyOS): drop GROUP="plugdev" (nonexistent on Arch, which made the whole rule fail) and rely on TAG+="uaccess". This was the root cause of the indicator not working on CachyOS.
  • XInput charging flag: the 0x12 report's charging/cable flag is byte 35 (not byte 37, which never changes) — confirmed via plug/unplug captures and covered by a parser test from the real frames. Charging now works in XInput too.

Naming

  • GNOME extension UUID → cyclone2-battery@vdemonchy.github.io; COSMIC app id → io.github.vdemonchy.Cyclone2Battery (the old @victor.local / dev.victor placeholders aren't suitable for public sharing).

Notes

  • The system power panel (UPower) only reflects Switch mode natively; the indicator and notifications cover all modes. Documented in the README.
  • XInput battery percentage scaling below 100% is read from byte 36 but unverified at lower charge (every capture so far has been at full) — tracked as a follow-up.

Testing

  • Go: go build ./..., go vet, go test ./... (incl. new notifier and real-frame charging parser tests) pass.
  • COSMIC crate: cargo build --release + cargo test pass.
  • GNOME gschema compiles (glib-compile-schemas --strict --dry-run).
  • Manually verified on COSMIC (CachyOS): applet in panel, udev ACL granted, notifications fire, breathing pulse, charging detection via live plug/unplug.

🤖 Generated with Claude Code

@vdemonchy
vdemonchy marked this pull request as draft June 4, 2026 08:51
@vdemonchy vdemonchy changed the title Add COSMIC desktop applet (CachyOS support) COSMIC applet + shared battery UX, udev fix, XInput charging Jun 5, 2026
vdemonchy and others added 18 commits June 5, 2026 11:46
Adds cosmic-applet/ with a minimal libcosmic skeleton that compiles
and renders an input-gaming-symbolic icon button in the COSMIC panel.
Pinned to libcosmic rev f0f68933 (master HEAD); requires Rust 1.93.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds AppletConfig with CosmicConfigEntry derive (poll_interval=60,
display_mode=IconText, show_controller_icon=true), daemon_config_dir()
honoring XDG_CONFIG_HOME, and write_daemon_interval() that writes the
exact bytes {"interval_seconds":N} expected by the daemon.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Implements the full libcosmic Application for the cyclone2-applet:
re-reads daemon state on each watcher tick, renders the panel button
(respecting visibility/display mode/controller-icon settings), and a
popup showing Mode + Battery with settings controls that persist via
cosmic-config and write the daemon's config.json.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The rule used GROUP="plugdev", which does not exist on Arch/CachyOS, so
udev rejected the whole rule line and never applied uaccess — leaving the
controller's hidraw node root-only and the daemon unable to read the
battery (permission denied). Rely solely on TAG+="uaccess", the
distro-agnostic logind mechanism; drop the redundant plugdev group/MODE.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Wrap the panel view in autosize_window and render the icon(s) + text
  inside a single AppletIcon button, so the surface sizes to its content
  and the indicator reads as one cohesive element (previously the text was
  clipped and the controller icon hid the rest).
- Drop the redundant battery glyph: the controller icon is now the sole
  icon and is tinted by battery level — green (>=60) / yellow (>=25) / red
  (<25) — falling back to the panel foreground colour when the level is
  unknown (missing / stale).
- Always show the controller icon; remove the show-controller-icon toggle.
- Reduce display modes to Icon only / Icon + text (drop Text only).
- Rename the popup label "Mode:" to "Cyclone 2 mode:".
- README: document the level colours, two display modes, and that the
  system power panel (UPower) is only reliable in Switch mode.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Mirror the COSMIC applet changes in the GNOME extension:
- Drop the redundant battery icon; the controller icon is the sole icon,
  tinted by battery level — green (>=60) / yellow (>=25) / red (<25) — via
  St.Icon CSS colour, neutral when the level is unknown (stale / no battery).
- Always show the controller icon; remove the show-controller-icon setting
  (gschema key + prefs switch).
- Reduce display modes to Icon only / Icon + text (drop Text only).
- Rename the popup label "Mode:" to "Cyclone 2 mode:".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
`@victor.local` is a reserved mDNS TLD, not an ownable domain, and a poor
UUID for a publicly shared extension. Rename to namespaces tied to the
GitHub account:
- GNOME extension UUID: cyclone2-battery@vdemonchy.github.io (dir,
  metadata.json, install.sh, README enable command).
- COSMIC applet app id: io.github.vdemonchy.Cyclone2Battery (APP_ID,
  .desktop filename, install.sh).

The gschema id and the extension JS don't reference the UUID, so they need
no change.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Post a desktop notification (via gdbus, so no D-Bus dependency) when the
battery first drops to or below a configurable threshold. The notifier is
edge-triggered with a 5% hysteresis margin and re-arms on charge/disconnect,
so a level hovering near the threshold doesn't spam the user. Stale/unknown
readings are ignored. Threshold comes from config.json
(low_battery_threshold; 0 disables).

Because the daemon reads the correct per-mode value, this works accurately in
all battery modes — including XInput and DS4, which the system power panel
(UPower) can't report correctly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- Always show the charge state in the popup ("— Charging" / "— On battery").
- Breathe the icon while charging: a sine-driven brightness pulse (~2s cycle,
  ~40% floor) via a timer subscription that runs only while charging.
- Configurable low-battery alert threshold (0–50% stepper, default 20%),
  written to the daemon's config.json alongside the poll interval (synced on
  startup too).
- Configurable battery level colors: green/yellow thresholds (defaults 60/25),
  with the green threshold constrained to stay above the yellow one.
- Rename the popup "Mode:" label to "Cyclone 2 mode:".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…(parity)

Mirror the COSMIC applet's new behavior in the GNOME extension:
- Always show the charge state in the menu ("— Charging" / "— On battery").
- Breathe the controller icon while charging via a looping, auto-reversing,
  sine-eased Clutter opacity transition (~2s cycle, ~40% floor).
- Configurable low-battery alert threshold (0–50% SpinRow, default 20%),
  written to config.json for the daemon.
- Configurable battery level colors: green/yellow thresholds (defaults 60/25),
  with each spinner bounded so green stays above yellow.
- Rename the popup "Mode:" label to "Cyclone 2 mode:".

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The XInput 0x12 report's charging flag is byte 35 (0 on battery, 1 plugged),
not byte 37. Confirmed by capturing frames across plug → unplug → plug cycles:
byte 35 tracked the cable state exactly while byte 37 stayed 0. The old code
read byte 37, so XInput charging never registered.

Read byte 35 instead, fix the bounds check (percent at 36 is now the highest
index), and add a parser test built from the real captured frames. Update
docs/protocol.md and the README to mark the flag confirmed.

Charging now works natively in all modes: DS4/Switch via the kernel
power_supply cable-state, XInput via byte 35.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@vdemonchy
vdemonchy marked this pull request as ready for review June 5, 2026 09:52
When the controller disconnected (Display::Hidden), view() returned a bare
Space that bypassed autosize_window, so the panel kept the applet surface at
its last size and left an empty gap. Wrap the empty element in
autosize_window so the surface shrinks to zero and the slot disappears.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant